package sysAuth

import initConfig.SysInitData

class SysRoles {

    String roleNo;
    String roleName ;
    String marks;
    String roleType; //目前角色类型定义三种吧：菜单角色、数据角色、通知权限(报表增删改)
    String creator ;//创建人
    String updater ;//更新人
    Date dateCreated;
    Date lastUpdated;
    static constraints = {
        roleNo(nullable: false,blank: false,unique: "roleType")
        marks(nullable: true )
        roleName(nullable: false)
        creator(nullable: true)
        updater(nullable: true)
    }
    static mapping = {
        version false
    }

    static init(){
        if(SysRoles.count ==0){
            //add sys roles
            new SysRoles(roleNo:SysInitData.ADMIN_FUNC_ROLE ,roleName: SysInitData.AdminRole.get(SysInitData.ADMIN_FUNC_ROLE),roleType: SysInitData.FUNC_ROLE,creator:SysInitData.SYS_ADMIN).save(flush: true)
            new SysRoles(roleNo:SysInitData.ADMIN_DATA_ROLE,roleName: SysInitData.AdminRole.get(SysInitData.ADMIN_DATA_ROLE),roleType: SysInitData.DATA_ROLE,creator:SysInitData.SYS_ADMIN).save(flush: true)
            //add test roles
            new SysRoles(roleNo: SysInitData.TEST_NAME,roleName: SysInitData.TEST_NAME,roleType: SysInitData.FUNC_ROLE,creator:SysInitData.SYS_ADMIN).save(flush: true)
            new SysRoles(roleNo: SysInitData.TEST_NAME,roleName: SysInitData.TEST_NAME,roleType: SysInitData.DATA_ROLE,creator:SysInitData.SYS_ADMIN).save(flush: true)
        }
    }
}
